<template>
	<up-tabs :list="list1" :scrollable="false" @click="click" :current="index" lineColor="#E94816"></up-tabs>
	<view class="after-box">
		<block v-if="proList.length>0">
		<block v-for="(item,index) in proList" :key="index">
			<view class="order-item" @click="look(item.id)">
				<view class="top">
					<span>订单编号：{{item.refund_no}}</span>
					<span v-if="item.status == 1">待审核</span>
					<span v-if="item.status == 2">已通过</span>
					<span v-if="item.status == 3">已拒绝</span>
					<span v-if="item.status == 4">已取消</span>
				</view>
				<up-divider></up-divider>
				<block v-for="(proitem,proindex) in item.deatils" :key="proindex">
					<view class="bottom">
						<img :src="proitem.order.picture" alt="" class="left" />
						<view class="right">
							<view class="name_price">
								<view class="name">
									{{proitem.order.goods_name}}
								</view>
								<view class="price">
									￥
									<text class="text">{{proitem.order.price}}</text>
								</view>
							</view>
							<view class="size">
								<span>{{proitem.order.attr}}</span> x{{proitem.order.num}}
							</view>
						</view>
					</view>
				</block>
				<view class="btn-box">
					<view class="price">
						实付款￥
						<text class="text">{{item.order_amount}}</text>
					</view>
					<!-- 售后申请 -->
					<view class="btn" v-if="index == 1">
						<up-button type="info" customStyle="width: 140rpx;height: 62rpx;margin-top:20rpx" shape="circle"
							:plain="true" :hairline="true" color="#292A2E" text="申请售后" @click.stop="apply(item)"></up-button>
					</view>
					<!-- 待收货 -->
					<view class="btn" v-if="item.status == 2 && index!=1">
						<up-button type="info" customStyle="width: 140rpx;height: 62rpx;margin-top:20rpx;margin-right:10rpx" shape="circle" :plain="true" :hairline="true" color="#908E8E" text="撤销申请"></up-button>
						<up-button type="info" customStyle="width: 140rpx;height: 62rpx;margin-top:20rpx" shape="circle" :plain="true" :hairline="true" color="#292A2E" text="查看详情" @click.stop="look()"></up-button>
					</view>
					<!-- 已完成 -->
					<view class="btn" v-if="item.status == 5 && index!=1">
						<view style="width: 676rpx;height: 62rpx;border-radius: 4rpx;background: #EFEFEF;font-size: 24rpx;line-height: 62rpx;">
							&nbsp;&nbsp; 完成 &nbsp;&nbsp;<span>服务已完成，感谢您对捌加壹采购的支持</span>
						</view>
					</view>
				</view>
			</view>
		</block>
		</block>
		<block v-else>
			<view class="empty-shop-car" >
				<image src="../../static/afterSale.png" class="empty-shop-car-image" mode=""></image>
				<text style="color: #999999;">暂无售后订单</text>
			</view>
		</block>
		<salepop ref='afterSale'></salepop>
	</view>
</template>

<script>
	import {
		http
	} from 'uview-plus'
	import salepop from '@/componets/after-sale-pop/after-sale-pop.vue'
	export default {
		components: {
			salepop
		},
		data() {
			return {
				list1: [{
						name: '售后申请'
					},
					{
						name: '处理中'
					},
					{
						name: '申请记录'
					}
				],
				proList:[],
				index:0
			}
		},
		async onLoad() {
			if(this.index == 0){
				this.can_applyList()
			}
		},
		methods: {
			//展示售后列表
			async can_applyList(){
				await http.get('/shop/after/sale/may').then(res => {
					console.log(res)
					this.proList = res.data
				})
			},
			//tab切换
			click(e){
				if(e.index == 0){
					this.can_applyList()
				}else if(e.index == 1){
					this.applyList(2)
				}else{
					this.applyList()
				}
			},
			//售后列表
			async applyList(e){
				await http.get('/shop/after/sale',{params:{status:e}}).then(res => {
					console.log(res);
					this.proList = res.items
				})
			},
			apply(e) {
				this.$refs.afterSale.setup(e);
			},
			look(e) {
				uni.navigateTo({
					url: '/pages/after_sale/after_sale_info?after_sale_id='+e
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F9F9F9;
	}
.empty-shop-car {
		width: 750rpx;
		min-height: 680rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		.empty-shop-car-image {
			width: 460rpx;
			height: 460rpx;
			margin-top: 102rpx;
		}

		text {
			margin-top: 40rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #fff;
		}

		.empty-shop-car-btn {
			width: 240rpx;
			height: 90rpx;
			background: $main-color;
			border-radius: 200rpx;
			margin-top: 40rpx;
			text-align: center;
			line-height: 90rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: #999999;
		}
	}
	.after-box {
		.order-item {
			width: 718rpx;
			border-radius: 20px;
			margin: 16rpx auto;
			opacity: 1;
			background: #FFFFFF;
			padding: 24rpx 20rpx;
			box-sizing: border-box;

			.top {
				font-size: 26rpx;
				font-weight: normal;
				color: #8D8989;
				@include flex(row);
				justify-content: space-between;
				align-items: center;
			}

			.middle {
				width: 678rpx;
				height: 156rpx;
				border-radius: 10rpx;
				opacity: 1;
				margin: auto;
				margin-bottom: 20rpx;
				background: #F9F9F9;
				padding: 20rpx;
				box-sizing: border-box;
				@include flex(row);
				align-items: center;
				justify-content: space-between;

				.middle_left {
					height: 100%;

					.img {
						width: 32.48rpx;
						height: 32rpx;
					}
				}

				.middle_middle {
					height: 100%;
					width: 600rpx;
					margin-left: 14rpx;
					@include flex(column);
					justify-content: space-between;
					font-size: 24rpx;
					color: #8D8989;
					line-height: 37.44rpx;

					.status {
						font-size: 28rpx;
						color: #3D3D3D;
					}
				}
			}

			.bottom {
				@include flex(row);

				.left {
					width: 150rpx;
					height: 150rpx;
				}

				.right {
					flex: 1;
					margin-left: 12rpx;
					font-size: 28rpx;
					font-weight: normal;
					color: #272727;

					.name_price {
						@include flex(row);
						justify-content: space-between;

						.name {
							width: 300rpx;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
						}


					}

					.size {
						width: 100%;
						font-size: 24rpx;
						font-weight: normal;
						color: #737373;
						margin-top: 6rpx;
						display: flex;
						justify-content: space-between
					}
				}

			}

			.btn-box {
				@include flex(column);
				justify-content: flex-end;
				align-items: flex-end;

				.btn {
					@include flex(row)
				}
			}

			.price {
				font-size: 20rpx;

				.text {
					font-weight: 500;
					font-size: 28rpx;
				}
			}
		}
	}
</style>